package CSDN;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 王圆豪
 * Date: 2025-05-26
 * Time: 13:36
 */

public class Test28 {
    public static void main(String[] args) {
        Object locker = new Object();
        for (int i = 0; i < 1000; i++) {
            //需要执行1000次的加锁和解锁
            synchronized (locker) {
                System.out.println("hello");
            }
        }

        //只需要执行一次加锁和解锁
        synchronized (locker) {
            for (int i = 0; i < 1000; i++) {
                System.out.println("hello");
            }
        }
    }
}
